//
//  AJTTMineModel.swift
//  JourneyThroughTime
//
//  Created by iOS-Czz on 2023/11/6.
//

import UIKit

class AJTTMineViewModel{
    var dataSource = [AJTTMineModel]()
}
extension AJTTMineViewModel{
    func getPageData(onSuccess: ((_ models: [AJTTMineModel]) ->Void)?){
        let dataHelper = AJTTMineModel.getUsingLKDBHelper()
        let sql = "select * from @t"
        let modelArr = dataHelper.search(withSQL: sql, to: AJTTMineModel.self) as! [AJTTMineModel]
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "yyyy-MM-dd"
        let sortedModels = modelArr.sorted { (model1, model2) -> Bool in
            guard let date1 = dateFormatter.date(from: model1.date),
                  let date2 = dateFormatter.date(from: model2.date) else {
                return false // 如果转换失败则直接返回 false
            }
            return date1 > date2
        }
        self.dataSource = sortedModels
        onSuccess?(self.dataSource)
    }
}

@objcMembers
class AJTTMineModel: AJTTBaseModel,Codable {
    var content = ""
    var picture = ""
    var date = ""
    var isDefault = true
    override class func getTableName() -> String {
        return  String(describing: AJTTMineModel.self)
    }
}
